package com.yin.myproject.io;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @author Eason
 * @create 2018-04-04 16:31
 **/
public class ByteArrayStreamDemo {
    public static void main(String[] args) throws IOException {
        String cotent = "abcedefghi中国人";
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        bout.write(cotent.getBytes());
        byte[] buff = bout.toByteArray();
        System.out.println(new String(buff, "utf-8"));
        System.out.println("***********************");

        ByteArrayInputStream bin = new ByteArrayInputStream(cotent.getBytes());
        int b;
        byte[] buffer = new byte[1024];
        while ((b = bin.read(buffer, 0, buffer.length)) != -1) {
            System.out.println(new String(buffer, "utf-8"));
        }
    }
}
